package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.ProschedueTask;
import com.qidianit.mes.pojo.pro.Workflow;
import com.qidianit.mes.pro.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description:
 * @Author: YanJiRan
 * @Date: 2025/9/18 - 下午1:36
 */
@RestController
@RequestMapping("/workflow")
public class WorkflowController {
    @Autowired
    private WorkflowService workflowService;

    @GetMapping("/selectByMaterialCode")
    public Result<List<Workflow>> selectByMaterialCode(String materialCode){
        return workflowService.selectListByMaterialCode(materialCode);
    };

    @GetMapping("/page")
    public Result<PageInfo<Workflow>> list(Workflow workflow, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size){
        return workflowService.selectList(workflow,page,size);
    }

    @GetMapping("code/{code}")
    public Result<Workflow> getByCode(@PathVariable("code") String workflowCode){
        return workflowService.selectByCode(workflowCode);
    }

    @PostMapping("/add")
    public Result<Workflow> save(@RequestBody Workflow workflow){
        return workflowService.saveWorkflow(workflow);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Workflow workflow){
        return workflowService.updateById(workflow);
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Long id){
        return workflowService.deleteById(id);
    }

    @DeleteMapping("/batchDelete")
    public Result batchDelete(Long[] id){
        return workflowService.batchDelete(id);
    }
}
